<%@ page import="java.util.ArrayList" %>
<%@ page import="java.util.Collections" %>
<%@ page contentType="text/html;charset=UTF-8" language="java" isELIgnored="false" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<html>
<head>
    <title>Title</title>
</head>
<body>
    <h1>IF标签测试</h1>
    <form action="JSTL.jsp" method="post" accept-charset="UTF-8">
        <label for="username">用户名: </label>
        <input type="text" id="username" name="username" value="${param.username}">
        <%--${}使用EL表达式--%>
        <input type="submit" value="提交"><br>
    </form>

    <c:if test="${param.username == 'lin'}" var="isLin">
        <h3>
            <c:out value="验证成功: ${param.username}" />
        </h3>
    </c:if>

    <c:if test="${param.username != null}">
        <c:if test="${param.username != 'lin'}">
            <h3>
                <c:out value="验证失败: ${param.username}" />
            </h3>
        </c:if>
    </c:if>
<%-------------------------------------------------------------%>
    <h1>Set标签测试</h1>
    <c:set var="password" value="1245" />
    <h3>Set值为: ${password}</h3>
<%-------------------------------------------------------------%>

    <h1>Choose-When-Otherwise标签测试</h1>
    <c:choose>
        <c:when test="${password==12345}">
            <h3>密码正确: ${password}</h3>
        </c:when>
        <c:when test="${password==54321}">
            <h3>密码正确: ${password}</h3>
        </c:when>
        <c:otherwise>
            <h3>密码错误! ${password}</h3>
        </c:otherwise>
    </c:choose>

<%-------------------------------------------------------------%>

    <h1>Foreach标签测试</h1>
    <%
        ArrayList<String> people = new ArrayList<>();
        Collections.addAll(people, "lin", "lin2", "lin3", "lin4");
        request.setAttribute("people", people);
    %>
    <c:forEach items="${people}" var="person">
        <c:out value="${people}" /><br>
    </c:forEach>
<hr>
    <c:forEach items="${people}" var="person" begin="0" end="${(people.size())}" step="2">
        <c:out value="${person}" /><br>
    </c:forEach>
</body>
</html>
